# tools/string_tool.py
import re
import logging

def to_uppercase(s: str) -> str:
    return s.upper()

def to_lowercase(s: str) -> str:
    return s.lower()

def toggle_case(s: str) -> str:
    return s.swapcase()

def camel_case(s: str) -> str:
    """将下划线分隔的字符串或普通字符串转换为驼峰命名，支持连续英文单词"""
    # 使用正则表达式分割字符串，保留单词边界
    words = re.split(r'[_\s]+', s)
    # 处理每个单词，首字母小写，其余单词首字母大写
    return words[0].lower() + ''.join(word.capitalize() for word in words[1:])


def run():
    print("\n欢迎使用字符串操作工具")
    print("1. 转换为大写")
    print("2. 转换为小写")
    print("3. 生成随机字符串")
    print("4. 生成 UUID")
    print("5. 大小写切换")
    print("6. 驼峰化")
    choice = input("请选择操作（1-6）：")
    if choice == "1":
        s = input("请输入字符串：")
        result = to_uppercase(s)
        print(f"结果：{result}")
    elif choice == "2":
        s = input("请输入字符串：")
        result = to_lowercase(s)
        print(f"结果：{result}")
    elif choice == "3":
        length = int(input("请输入随机字符串的长度："))
        result = ''.join(random.choices(string.ascii_letters + string.digits, k=length))
        print(f"生成的随机字符串：{result}")
    elif choice == "4":
        import uuid
        result = str(uuid.uuid4())
        print(f"生成的 UUID：{result}")
    elif choice == "5":
        s = input("请输入字符串：")
        result = toggle_case(s)
        print(f"大小写切换结果：{result}")
    elif choice == "6":
        s = input("请输入字符串：")
        result = camel_case(s)
        print(f"驼峰化结果：{result}")
    else:
        print("无效选项！")